import request from '@/utils/request'

export interface SDResponse {
  data: {
    available?: boolean
    images?: string[]
    error?: string
    image?: string
    models?: string[]
    lora_models?: string[]
    success?: boolean
  }
}

export interface GenerateParams {
  prompt: string
  model?: string
  negative_prompt?: string
  width?: number
  height?: number
  steps?: number
  cfg_scale?: number
  seed?: number
  enable_hr?: boolean
  denoising_strength?: number
  upscaler_scale?: number
  upscaler_name?: string
  sampler_name?: string
  config_name?: string
  lora_model?: string
  lora_weight?: number
  batch_count?: number
  batch_size?: number
  hr_resize_mode?: 'scale' | 'size'
  hr_target_width?: number
  hr_target_height?: number
}

export interface BatchGenerateParams extends GenerateParams {
  prompts: string[]
}

export const sdApi = {
  async checkStatus(): Promise<SDResponse> {
    return await request.get<SDResponse>('/sd/check_sd_status')
  },

  async getModels(): Promise<SDResponse> {
    return await request.get<SDResponse>('/sd/models')
  },

  async getLoraModels(): Promise<SDResponse> {
    return await request.get<SDResponse>('/sd/lora_models')
  },

  async generate(params: GenerateParams): Promise<SDResponse> {
    return await request.post<SDResponse>('/sd/generate', params)
  },

  async batchGenerate(params: BatchGenerateParams): Promise<SDResponse> {
    return await request.post<SDResponse>('/sd/batch_generate', params)
  }
}
